package dou;

import java.util.Random;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

public class T10 {
    static CyclicBarrier bar = new CyclicBarrier(3, () -> System.out.println("人齐了，开饭！"));

    static void eat() {
        var tn = Thread.currentThread().getName();
        Random rand = new Random();
        int s = rand.nextInt(14) + 2;
        System.out.println(tn + "还需" + s + "秒");
        try {

            TimeUnit.SECONDS.sleep(s);
            System.out.println(tn + ":到了");
            bar.await();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Thread(T10::eat, "张三").start();
        new Thread(T10::eat, "张四").start();
        new Thread(T10::eat, "张五").start();
        new Thread(T10::eat, "张六").start();
        new Thread(T10::eat, "张其").start();
    }
}
